﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using BussinesLogic;
using System.Collections;

namespace DataAccess.Factory
{
    class ExpedienteFactoryDao : BaseFactory
    {

        public ExpedienteFactoryDao()
        {
            this.classType = typeof(Expediente);
        }

        private string uspGetExpediente = @"fd_Expediente_get_Expediente";
        private string uspGetExpedientes = @"fd_Expediente_Gets";
        private string uspCreateExpediente = @"fd_Expediente_Create";

        /* funciones */

        public Expediente getExpediente(string NoExpediente)
        {
            SqlParameter [] parameter = new SqlParameter[1];

            parameter[0] = new SqlParameter("@NoExpediente", NoExpediente);

            ArrayList obj = this.DataTableToObjectList(parameter, this.uspGetExpediente);

            if (obj != null && obj.Count > 0)
            {
                return (Expediente)obj[0];
            }
            else
            {
                return null;
            }
            
        }
        public ArrayList getExpedientes()
        {
            SqlParameter[] parameter = new SqlParameter[0];

            ArrayList obj = this.DataTableToObjectList(parameter, this.uspGetExpedientes);
            
            if (obj != null && obj.Count > 0)
            {
                return obj;
            }
            else
            {
                return null;
            }

        }

        public DataTable getExpedientesTalbe()
        {
            SqlParameter[] parameter = new SqlParameter[0];

            return this.DataTableList(parameter, this.uspGetExpedientes);

        }

        public int createExpediente(string xmlUser)
        {
            SqlParameter[] parameter = new SqlParameter[2];

            parameter[0] = new SqlParameter("@expediente", xmlUser);
            parameter[1] = new SqlParameter("@ID", SqlDbType.Int);
            parameter[1].Direction = ParameterDirection.Output;

            this.executeNoQuery(parameter, this.uspCreateExpediente);

            return (int)parameter[1].Value;
        }
    }
}
